package LeetCode.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * 杨辉三角
 * @author: leiwenkang02@meituan.com
 * @date: 2018/8/13
 * @time: 18:15
 */
public class Test118杨辉三角 {
    public static void main(String[] args) {
        List<List<Integer>> result = generate(5);
        System.out.println(result);
    }

    public static List<List<Integer>> generate(int numRows) {
        if (numRows <= 0) {
            return new ArrayList<>();
        }
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        list.add(1);
        result.add(list);

        for (int i = 1; i < numRows; i++) {
            List<Integer> before = result.get(result.size() - 1);
            List<Integer> next = new ArrayList<>();
            next.add(1);
            for (int j = 0; j < before.size() - 1; j++) {
                next.add(before.get(j) + before.get(j + 1));

            }
            next.add(1);
            result.add(next);
        }
        return result;
    }
}
